import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  // 获取字典列表
  getDictList = '/base/dict/page/list',
  // 创建字典
  createDict = '/base/dict/create',
  // 更新字典
  updateDict = '/base/dict/update',
  // 删除字典
  dict = '/base/dict',
  // 获取字典项列表
  getDictItemList = '/base/dict/item/page/list',
  // 创建字典项
  createDictItem = '/base/dict/item/create',
  // 更新字典项
  updateDictItem = '/base/dict/item/update',
  // 删除字典项
  dictItem = '/base/dict/item/',
}

export function getDictList(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.getDictList;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function createDict(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createDict;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function updateDict(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateDict;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function deleteDictById(id: number, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.dict}/${id}`;
  return defHttp.delete(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function getDictItemList(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.getDictItemList;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function createDictItem(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createDictItem;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}
export function updateDictItem(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateDictItem;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}
export function deleteDictItemById(id: number, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.dictItem}/${id}`;
  return defHttp.delete(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}
